package com.personnalManagerSystem.controller;


import com.personnalManagerSystem.model.Permission;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import sun.security.krb5.internal.PAData;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liqing
 * @since 2022-03-27
 */
@Controller
@RequestMapping("/permission")
public class PermissionController extends BaseController{
    @RequestMapping("/list")
    public String list(Model model,
                       String option,
                       String searchContent,
                       Integer pageNum,
                       Integer pageSize){
        baseList(model,option,searchContent,pageNum,pageSize,iPermissionService);
        List<Permission> permissionList = iPermissionService.list();
        model.addAttribute("permissionList",permissionList);
        return "view/permission";
    }
    @RequestMapping("/add")
    public String add(Permission permission){
        //System.out.println("permission:"+permission);
        iPermissionService.save(permission);
        return "redirect:/permission/list";
    }
    @RequestMapping("/del")
    public String del(@RequestParam("permissionId") Integer permissionId){
        //System.out.println("permissionId:"+permissionId);
        iPermissionService.removeById(permissionId);
        return "redirect:/permission/list";
    }

    @RequestMapping("/edit")
    public String edit(Permission permission){
        //System.out.println("permission:"+permission);
        iPermissionService.saveOrUpdate(permission);
        return "redirect:/permission/list";
    }

}

